package game;

import java.awt.*;

/**
 * 游戏物体的父类
 */
public class GameObject {
     Image img;//图片
     double x,y;//坐标轴，位置
     int speed;//速度
     int width,height;//宽高

    public void drawSelf(Graphics g){
        g.drawImage(img,(int)x,(int) y,null);
    }
    public GameObject() {
    }

    public GameObject(Image img, double x, double y,int speed) {
        this.img = img;
        this.x = x;
        this.y = y;
        this.speed = speed;
    }

    public GameObject(Image img, double x, double y, int speed, int width, int height) {
        this.img = img;
        this.x = x;
        this.y = y;
        this.speed = speed;
        this.width = width;
        this.height = height;
    }

    /**
     * 定义一个方法来获取返回的数据
     * 返回物体所在的矩形。便于后续的碰撞监测
     * @return
     * javaAPI提供了Rectangle类来表示矩形相关信息，并且提供了intersects()方法，来判断矩形是否相交
     */
    public Rectangle getRect(){
        return new Rectangle((int) x,(int) y,width,height);
    }


}
